package com.iot.core.data.service;

import com.iot.core.data.entity.HtRoleMenu;
import com.iot.core.data.mapper.HtRoleMenuMapper;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

import static com.iot.core.data.entity.table.HtMenuTableDef.HT_MENU;
import static com.iot.core.data.entity.table.HtPageAuthTableDef.HT_PAGE_AUTH;
import static com.iot.core.data.entity.table.HtPageTableDef.HT_PAGE;
import static com.iot.core.data.entity.table.HtRoleMenuTableDef.HT_ROLE_MENU;

@Service
public class HtRoleMenuServiceImpl extends  ServiceImpl<HtRoleMenuMapper, HtRoleMenu> implements IHtRoleMenuService {


    public List<String> getRolesUrls(List<Long> lrids){

        var qw= QueryWrapper.create()
                .select(HT_PAGE_AUTH.URLS)
                .from(HT_ROLE_MENU).as("a")
                .join(HT_MENU).as("b").on( HT_ROLE_MENU.HTROLE_ID.in(lrids).and(HT_ROLE_MENU.HTROLE_ID.eq(HT_MENU.ID))  )
                .join(HT_PAGE).as("c").on(HT_MENU.HTPAGE_ID.eq(HT_PAGE.ID))
                .join(HT_PAGE_AUTH).as("d").on(HT_PAGE.ID .eq(HT_PAGE_AUTH.HTPAGE_ID) )
                ;
        var l=getMapper().selectListByQueryAs(qw,String.class);
        return l;
    }
    public   List<Long> getRolesMenuIds(List<Long> lrids){
        var qw= QueryWrapper.create()
                .select(HT_ROLE_MENU.HTMENU_ID)
                .from(HT_ROLE_MENU).as("a")
                .where(   HT_ROLE_MENU.HTROLE_ID.in(lrids)  )
                ;

        var l=getMapper().selectListByQueryAs(qw,Long.class);
        l=l.stream().distinct().collect(Collectors.toList());
        return l;
    }
}
